<template>
  <div class="app-container">
    <el-input
      v-model="filterText"
      placeholder="请输入过滤条件"
      style="margin-bottom: 30px"
    />

    <el-tree
      ref="tree"
      :data="list"
      :props="defaultProps"
      :filter-node-method="filterNode"
      class="filter-tree"
      default-expand-all
    />
  </div>
</template>
<script>
import subjectApi from "@/api/edu/subject";
export default {
  data() {
    return {
      filterText: '',
      list: [],  //返回所有分类数据
      defaultProps: {
        children: 'children',
        label: 'title'
      }
    }
  },
  watch: {
    filterText(val) {
      this.$refs.tree.filter(val);
    }
  },
  created() { this.getSubjectTreeList() },
  methods: {
    getSubjectTreeList() {
        subjectApi.getSubjectTreeList().then(response => this.list = response.data.list)
    },
    filterNode(value, data) {
      if (!value) return true
      return data.title.toLowerCase().indexOf(value.toLowerCase()) !== -1
    }
  },
};
</script>